﻿using UnityEngine;
using System.Collections;
using System.IO;

public class TestEffectTrigger : MonoBehaviour {
	public enum BUTTON_MODE
	{
		PLAY,
		PAUSE,
		STOP
	};

	public GameObject Effect;
	public BUTTON_MODE[] buttonModes; 

	GameObject createdEffect;

	// Use this for initialization
	void Start () {
		if( Effect != null )
			createdEffect = Instantiate(Effect, Vector3.zero, Quaternion.identity) as GameObject;
        //DirectoryInfo dicInfo = new DirectoryInfo(Application.dataPath + "/Resources/Prefabs");
        //foreach (DirectoryInfo info in dicInfo.GetDirectories())
        //{
        //    foreach (FileInfo fileInfo in info.GetFiles())
        //    {
        //        if (fileInfo.Name.Contains("FX") || fileInfo.Name.Contains("Fx"))
        //            Debug.LogError(fileInfo.Name);
        //    }
        //}
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	float buttonSpace = 200f;

	void OnGUI()
	{
		for(int i=0; i<buttonModes.Length; i++)
		{
			if( GUI.Button(new Rect(0, buttonSpace*(i+1), 75f,75f), buttonModes[i].ToString()) )
			{
				if( buttonModes[i] == BUTTON_MODE.PLAY )
				{
					if( createdEffect.GetComponentsInChildren<ParticleSystem>() != null )
					{
						ParticleSystem[] particles = createdEffect.GetComponentsInChildren<ParticleSystem>();
						foreach(ParticleSystem system in particles)
						{
							system.Play();
						}
					}
					if( createdEffect.GetComponentsInChildren<Animation>() != null )
					{
						Animation[] animations = createdEffect.GetComponentsInChildren<Animation>();
						foreach(Animation animation in animations)
						{
							animation.Play();
						}
					}
				}
				else if( buttonModes[i] == BUTTON_MODE.PAUSE )
				{
					if( createdEffect.GetComponentsInChildren<ParticleSystem>() != null )
					{
						ParticleSystem[] particles = createdEffect.GetComponentsInChildren<ParticleSystem>();
						foreach(ParticleSystem system in particles)
						{
							system.Pause();
						}
					}
					if( createdEffect.GetComponentsInChildren<Animation>() != null )
					{
						Animation[] animations = createdEffect.GetComponentsInChildren<Animation>();
						foreach(Animation animation in animations)
						{
							animation.Stop();
						}
					}
				}
				else if( buttonModes[i] == BUTTON_MODE.STOP )
				{
					if( createdEffect.GetComponentsInChildren<ParticleSystem>() != null )
					{
						ParticleSystem[] particles = createdEffect.GetComponentsInChildren<ParticleSystem>();
						foreach(ParticleSystem system in particles)
						{
							system.Stop();
						}
					}
					if( createdEffect.GetComponentsInChildren<Animation>() != null )
					{
						Animation[] animations = createdEffect.GetComponentsInChildren<Animation>();
						foreach(Animation animation in animations)
						{
							animation.Stop();
						}
					}
				}
			}
		}
	}
}
